/*
 * PSDetectCentroid.java
 *
 * Created on 8 de diciembre de 2007, 04:40 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Behaviors.Schemas.Perception;
import Behaviors.Schemas.Schema;
import Behaviors.Schemas.Vector2dSchema;
import Robot.Position2d;
import Util.Vector2d;
/**
 *
 * @author nxbot
 */
public class PSDetectCentroid extends Schema implements Vector2dSchema{
    Position2d [] positions=null;
    
    
    /** Creates a new instance of PSDetectCentroid */
    public PSDetectCentroid(String name,Position2d [] positions) {
        super(name);
        this.positions=positions;
    }
    
    public Vector2d Value(){
        Vector2d [] vectorPositions=new Vector2d[positions.length];
        for(int i=0;i<positions.length;i++){
            vectorPositions[i]=positions[i].getPositionVector();        
        }
        
        Vector2d average=Vector2d.averageVector(vectorPositions);
        
        //System.out.println("Average: "+average.toString());
        return average;
    }
}
